package com.zhanvie.singleton;

import java.util.concurrent.atomic.AtomicBoolean;

public class RunState {

    private RunState() {};

    private final AtomicBoolean runState = new AtomicBoolean(false);

    private String progPid = null;

    private static class SingletonInner {
        private static final RunState instance = new RunState();
    }

    public static RunState getInstance() {
        return SingletonInner.instance;
    }

    public void start() {
        runState.compareAndSet(false, true);
    }

    public void stop() {
        runState.compareAndSet(true, false);
    }

    public boolean isRunning() {
        return runState.get();
    }

    public void setPid(long pid) {
        progPid = String.join("", "", String.valueOf(pid));
    }

    public String getPid() {
        return progPid;
    }

}
